<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit sign() and verify() test of 'jws.js'</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../ext/json-sans-eval.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/keyutil-1.0.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>

<script src="../src/jws-3.3.js"></script>

<script type="text/javascript">
$(document).ready(function(){

// _test/z1.prv.p5p.pem (RSA)
var z1PrvPemP5P = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIBOgIBAAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4x\n" +
"EnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQJAeLvFTGRnlemmI8sPkSx/\n" +
"n2hhcRVg5Xut4h3tL32Vefhicvq55xqycoLCdgxATa5qyKOrhSz2vNVi+a/4JHom\n" +
"TQIhAP6b1FCGazJVYU/el2p2rAsdWDDdpk9TWblG2FErwSOfAiEA6atoD18F27D0\n" +
"MRsOb0No9IdKEjiXnYvGAMNcbyBwfAcCIQDVSctpjcF9T+MOWoTzrehgAzwe639n\n" +
"0oZGXJ/YF9RbNwIgGEm0u0RJO5idCS2ixnXfRut5C4POXpXUsuebiAF7L6kCIH0m\n" +
"GpYlbUmwIMsdWH7N4Sfgk6TSs0zb/xcfNBJbWFep\n" +
"-----END RSA PRIVATE KEY-----\n";

// _test/z1.prv.p5e.pem (RSA)
var z1PrvPemP5E = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,4626F2E5853E783F\n" +
"\n" +
"3vFpkrnbantC8RSzng2+jBw/VX95oi0VGKP0G8whENHUOVQXB/YOUSj+n80Y0Wwc\n" +
"GpeQi8U0FQdWyYv8b9aioeFB06r9t9mJsYscJ/wcIvv5tTMkr89cwN3+4GQQuqNg\n" +
"TmI9ekeoZ3NP26hTM4XTuFqHx4dzNNwjDLc8txc77WE/o4J4p8k9Py5yPZjs9EKy\n" +
"wy/yxtqQYQuFj90OMEG1G89iHTZRcq4YTZYdqg6P/XEUvyjifN+7Nym8f2N9TDDn\n" +
"RJtApPQlrgXvUDQKz6Lu1ZYMwe94E9YdutDGQMbxixbiyxlcxrkb/oEHH5WP5qPG\n" +
"w/xzh08Ce2Ftba2Q860S8nznjyZFiv+lqSKBahbujgP/63ZL+JbAd4cYBqgm4g1C\n" +
"YwMhHJbaVCzwYduxdyK2JBYEosDZiDfnOP4DqPhJYpg=\n" +
"-----END RSA PRIVATE KEY-----\n";
var z1PrvPemP5EPass = "hoge";

// _test/z1.prv.p8e.pem (RSA)
var z1PrvPemP8E = "" +
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
"MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIyScsGkpMl3kCAggA\n" +
"MBQGCCqGSIb3DQMHBAiObBK7oyBAzwSCAWCkStExnU3pYBQAxRqDctg5QEO3Ic1d\n" +
"GsRW+JW0kNonUydoOSD/7DBglnSDowiQ69HCW4OmumSJIU0hewX0yburFuy6Zs/q\n" +
"DkWox7oxBCsgFmfmkKGcK0USeJ+LX+YZVbvCCvHZkd99pEqQSfkRu4DgXbWmo6Zv\n" +
"2A6VFyBhE9MFmYex8mHTZ5cchBzAiFWRzjpRX94F4vbUFoXPGrEbOLovM2VpZ8Df\n" +
"1nLuXhWYVHsXHWn+fm7TH4Xzh1mFYYkTiXL9ABwKKohEL2SQJzKpa9FZvOZAmlSe\n" +
"UgQxVQLM/ZC+o4Vs4JHqIu4Ek2bgjEqDzo2EPznpcCsQTcwOqhPwNjP4Y3ovn1Nm\n" +
"8i0Hx51OA0vjRZBvvduKM9d5kRAOg8jqLjeWU3KraWLuSJ96RTzlWFgw6PsML+RE\n" +
"LHfdKDjRT0NMEMRh892oBi828asvvSWO6HYcM0xclt0uakxJhVP/mtzA\n" +
"-----END ENCRYPTED PRIVATE KEY-----\n";
var z1PrvPemP8EPass = "passwd";

var z1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E\n" +
"8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQ==\n" +
"-----END PUBLIC KEY-----\n";

var z1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIBdTCCAR+gAwIBAgIBBTANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL\n" +
"MAkGA1UECgwCYTEwHhcNMTMwNTA0MDM0MTQxWhcNMjMwNTA0MDM0MTQxWjAaMQsw\n" +
"CQYDVQQGEwJVUzELMAkGA1UECgwCYTEwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA\n" +
"6GZN0rQFKRIVaPOzm8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJ\n" +
"URX++I951D6uWxpONRj9WQIDAQABo1AwTjAdBgNVHQ4EFgQUxUc+4gDI561wA9/1\n" +
"QguM3fTCDhUwHwYDVR0jBBgwFoAUxUc+4gDI561wA9/1QguM3fTCDhUwDAYDVR0T\n" +
"BAUwAwEB/zANBgkqhkiG9w0BAQUFAANBALL2k69LjwOYfDXv3TXJUAFGUqto+Noj\n" +
"CJLP08fOfNBZy+KAIy0GsrNU/3uRViqbuGqAnH9kFFwHQjOAFrAe8XQ=\n" +
"-----END CERTIFICATE-----\n";

// _test/z3.prv.p8p.pem (RSA)
var z3PrvPemP8P = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALDikFExZMEW5bws\n" +
"j9DckEA+Ai7jYe7+In5UHpsqCaqXlPlJQFpziDWDHp1IlWI6r+nZ/7AJhS3y6wbV\n" +
"rF8IN4ohKaga1LIL3RDfnGbm4QcF06rrE0vHkMALUu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G/qOGQIVaay4Ucr6ovDkykO5Hxn7OU7s\n" +
"Jp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwF\n" +
"wnxCsU5+UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUE\n" +
"f0YN3/Q0auBkdbDR/ES2PbgKTJdkjc/rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1W\n" +
"SwIDAQAB\n" +
"-----END PUBLIC KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k1.prv.p8p.pem (ECC NIST P-256)
var k1PrvPemP8P = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgEbVzfPnZPxfAyxqE\n" +
"ZV05laAoJAl+/6Xt2O4mOB611sOhRANCAASgFTKjwJAAU95g++/vzKWHkzAVmNMI\n" +
"tB5vTjZOOIwnEb70MsWZFIyUFD1P9Gwstz4+akHX7vI8BH6hHmBmfeQl\n" +
"-----END PRIVATE KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k1.pub.pem (ECC NIST P-256)
var k1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" +
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" +
"-----END PUBLIC KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k6.prv.p8p.pem (ECC NIST P-384)
var k6PrvPemP8P = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAamStb0Xep3y3sWw2u\n" +
"SSAdUPkgQ9Rvhlnx8XEVOYy2teh69T0on77ja02m03n8t8WhZANiAARUNSar38Rz\n" +
"lKPyZFsNSGUanzpNRth0C+MikVEH8FAlDHMMpAs34dyF4IK0uxgbiEe9bQ+ieLrl\n" +
"6xwFR0yaTivuwoyXC+ScGUnwnpaXmid6UUgw4ypbneHsaKuZ9JLdMAo=\n" +
"-----END PRIVATE KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k6.pub.p8.pem (ECC NIST P-384)
var k6PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEVDUmq9/Ec5Sj8mRbDUhlGp86TUbYdAvj\n" +
"IpFRB/BQJQxzDKQLN+HcheCCtLsYG4hHvW0Poni65escBUdMmk4r7sKMlwvknBlJ\n" +
"8J6Wl5onelFIMOMqW53h7GirmfSS3TAK\n" +
"-----END PUBLIC KEY-----\n";

// (ECC NIST P-521)
var k5PrvPemP8P = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIHuAgEAMBAGByqGSM49AgEGBSuBBAAjBIHWMIHTAgEBBEIBRNEQ8Y1gwDMH8pne\n" +
"z9uq4ODLE/KTx7eCzMNKlGRIhx/8Mo2+B9ORKPMFk4on0wFW7T+rp7NpXm1wxTOY\n" +
"HSTf7mWhgYkDgYYABADSmlI0TDURn/W+oZrgkPgC0F/56jGtzDFSTQEodep5E0Sw\n" +
"KvBrWN48PSbxukE9JdXPm2soe1yc9BC/Km6nrQJhnQDeIhUCoVSA8GTZ0EwL1AcT\n" +
"5YfKcvwwCdM4lHRU1jYXti4IpC/pggFT3N+IRFmS6M8gTYzvxCZMDUnYHimDB+1p\n" +
"jw==\n" +
"-----END PRIVATE KEY-----\n";

// (ECC NIST P-521)
var k5PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQA0ppSNEw1EZ/1vqGa4JD4AtBf+eox\n" +
"rcwxUk0BKHXqeRNEsCrwa1jePD0m8bpBPSXVz5trKHtcnPQQvypup60CYZ0A3iIV\n" +
"AqFUgPBk2dBMC9QHE+WHynL8MAnTOJR0VNY2F7YuCKQv6YIBU9zfiERZkujPIE2M\n" +
"78QmTA1J2B4pgwftaY8=\n" +
"-----END PUBLIC KEY-----\n";

// 1. sign test for algorithm name

test("algorithm test: unknown algorithm", function() {
  throws(function() {
    var sJWS = KJUR.jws.JWS.sign("unknown", '{"cty":"JWT"}', '{"age": 21}');
  },
  /^unsupported alg name: /,
  "raise exception 'unsupported alg name'");
});

test("algorithm test: none specifyed in args", function() {
  expect(1);
  var sJWS = KJUR.jws.JWS.sign("none", '{"cty":"JWT"}', '{"age": 21}');
  equal(sJWS, 'eyJjdHkiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhZ2UiOiAyMX0.', "1");
});

test("algorithm test: none", function() {
  expect(1);
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"none", "cty":"JWT"}', '{"age": 21}');
  equal(sJWS, 'eyJhbGciOiJub25lIiwgImN0eSI6IkpXVCJ9.eyJhZ2UiOiAyMX0.', "1");
});

var sJWSRS256 = 'eyJhbGciOiJSUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.inTO81veA1R6x_MYP9Y3HBY7AlJ5H_QYZPzCJTEMu7md4fVm_AwBY-uNqxnM31JUVWYazX1htv2KES_VXievD8qVxez6-S7K8y-oQ462rCENrko_GVHBm9C7SgkZEgsnZ2IlhYhcYOmBUESfAHJKak9gP6_azu6Vr8Nvwtx8Qjk';
test("algorithm test: RS256", function() {
  expect(1);
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"RS256", "cty":"JWT"}', '{"age": 21}', z3PrvPemP8P);
  equal(sJWS, sJWSRS256, "1");
});

var sJWSRS384 = 'eyJhbGciOiJSUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.e70NDbbhDRzya959TavPxOwkRdPyaFQqLPLjFdUNmd5yI1awH_cON5GUf8G9irt0FgA1Iro12ZoZt8Asj9DUFGfr6aeKQFOK8FT0I12lAVUhj4fCYGVfTxTKuPMKpnvwgZmhWgE2AZRDdecMlF1tTOlD3uScGgvpf7VmCLr1icw';
test("algorithm test: RS384", function() {
  expect(1);
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"RS384", "cty":"JWT"}', '{"age": 21}', z3PrvPemP8P);
  equal(sJWS, sJWSRS384, "1");
});

var sJWSRS512 = 'eyJhbGciOiJSUzUxMiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.iykhTFG81J1FjH9SbHEy-FvZDBZENDlgIss_thbbQU2d4dZEQ09-x80dkugKM8xvGXyffrsxLLothe0aHzZBZd0T-OhDcKMmzg_H90sVSYWHbrbkMWQ5YT3chCVEdBcXhmTXeWo_LW_QBK3xRZtfWrkTPDNOMsoLD6WmEfyyI0M';
test("algorithm test: RS512", function() {
  expect(1);
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"RS512", "cty":"JWT"}', '{"age": 21}', z3PrvPemP8P);
  equal(sJWS, sJWSRS512, "1");
});

test("sign test for algorithm ES256(NIST P-256 k1)", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"ES256", "cty":"JWT"}', '{"age": 21}', k1PrvPemP8P);
  var a = sJWS.split(".");
  expect(4);
  equal(a[0], 'eyJhbGciOiJFUzI1NiIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
  equal(a[2].length, (64 * 4 + 2) / 3, 'signature length');
});

test("sign test for algorithm ES384(NIST P-384 k6)", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"ES384", "cty":"JWT"}', '{"age": 21}', k6PrvPemP8P);
  var a = sJWS.split(".");
  expect(4);
  equal(a[0], 'eyJhbGciOiJFUzM4NCIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
  equal(a[2].length, (96 * 4) / 3, 'signature length');
});

test("sign test for algorithm ES512(NIST P-521 k5)", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"ES512", "cty":"JWT"}', '{"age": 21}', k5PrvPemP8P);
  var a = sJWS.split(".");
  expect(4);
  equal(a[0], 'eyJhbGciOiJFUzUxMiIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
  var min = (130 * 4 + 2) / 3;
  var max = (132 * 4) / 3;
  ok(a[2].length >= min && a[2].length <= max, 'signature length');
});

test("algorithm test: PS256", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"PS256", "cty":"JWT"}', '{"age": 21}', z3PrvPemP8P);
  var a = sJWS.split(".");
  expect(3);
  equal(a[0], 'eyJhbGciOiJQUzI1NiIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
});

test("algorithm test: PS384", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"PS384", "cty":"JWT"}', '{"age": 21}', z3PrvPemP8P);
  var a = sJWS.split(".");
  expect(3);
  equal(a[0], 'eyJhbGciOiJQUzM4NCIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
});

test("algorithm test: PS512", function() {
  var sJWS = KJUR.jws.JWS.sign(null, '{"alg":"PS512", "cty":"JWT"}', '{"age": 21}', z4PrvPemP8P);
  var a = sJWS.split(".");
  expect(3);
  equal(a[0], 'eyJhbGciOiJQUzUxMiIsICJjdHkiOiJKV1QifQ', "head");
  equal(a[1], 'eyJhZ2UiOiAyMX0', 'payload');
  equal(a[2] != '', true, 'sign exists');
});

// 2. loading key type test


// 2. verify test for algorithm name

/*
test("verify test for algorithm none", function() {
  expect(1);
  var result = KJUR.jws.JWS.verify('eyJjdHkiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhZ2UiOiAyMX0.');
  equal(result, true, "");
});

test("verify test for algorithm none with ignored key", function() {
  expect(1);
  var result = KJUR.jws.JWS.verify('eyJjdHkiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhZ2UiOiAyMX0.', 'ignored key');
  equal(result, true, "");
});
 */

test("verify test for algorithm RS256 z3", function() {
  expect(1);
  var result = KJUR.jws.JWS.verify(sJWSRS256, z3PubPemP8);
  equal(result, true, "");
});

test("verify test for algorithm RS384 z3", function() {
  expect(1);
  var result = KJUR.jws.JWS.verify(sJWSRS384, z3PubPemP8);
  equal(result, true, "");
});

test("verify test for algorithm RS512 z3", function() {
  expect(1);
  var result = KJUR.jws.JWS.verify(sJWSRS512, z3PubPemP8);
  equal(result, true, "");
});

test("verify test for algorithm ES256(NIST P-256 k1)", function() {
  expect(3);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.qVXC_4YMmTvrBDuOYbDzBFnhZynGMKIsMbzUGtCbUcTESk-szN170wRvnI1p2XPfK4Nmr9-Tv_DICzC24MPdrA', k1PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.llxxbdRworpUTi3WEFjpeagXN7nQNknQXzrdXWbRuFumT7eqWqn05Vux88ubYQ62nLfUOme5Ou0SGxJYd6MwYw', k1PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.5ChOZc5w9T0SSSQgUK806RA36YCZGvYnUwBlTXsjmzJvv8PJ3FuPvjno0W36q1NJOQe3oGEaRl9o-OGR-0h95A', k1PubPemP8), true, "1");
});

test("verify test for algorithm ES384(NIST P-384 k6)", function() {
  expect(3);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.ImFmrFvzlyl-BGHz8sdD6we6T1uCL5d6Q-oCWmDSh-q8eSL1bxPix7XZjxZGYJySw1On974Vw2NmzffgXvDPk7Ayvau0_fp0v4KUh4x6RcGKZDQgXVli1mfrGKTFP37C', k6PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.Ay21GOTDEXWXr2svATEXAmDBVOVX38G4vSf5HJ9Nfqn1IggP1EDQQU6sJYPunNGkW7dQOZ5fOsgU9WibnOCrz73D3NDNDW5lVtFDmSp3dPQz_pddyv_SzOgXh81tlx-o', k6PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.1z6jcEq6MZxqRSdzGW7scWe-un0IQsB87EsUPY5HipsOrlusPcTAKGkGAodrQEEVxfGca2OCssfKdTH_lTwscmfuUayZDK9XzohB7tf6E92RI4Faox0AcicG-WXAH4fS', k6PubPemP8), true, "1");
});

test("verify test for algorithm ES512(NIST P-521 k5)", function() {
  expect(3);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzUxMiIsImN0eSI6IkpXVCJ9.eyJhZ2UiOiAyMX0.AIKp4hQBsuzi4MRGQxmLApgXwsddXNKmCaEp10nDt85scVDVNo2e3ky7dSo1tDmnP9oEXrQysUUL6asrVSVvz0cvAcpoFq2efdKd5qiDt48actcAH55TnbtFNn_-2dgXigeapDrvGWU1nBCvu_Eta-kW9IavO8PI3_bnTKhO80zRK3tY', k5PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzUxMiIsImN0eSI6IkpXVCJ9.eyJhZ2UiOiAyMX0.ADBsjngn209INTUgHnNb3FLjqGkLIssvsvFK9wGzSMj7wJeCZ4MhH764gI9jZCiixuvuUk-0AWdGU6q_t6WOcjVUADfyFfIZS8vkM-OHOQ2d9-kcHUJanWfK4PzkdHyVUZHMiEHJ2aaihgVVI9VjGA3bhmrLhjKG7xE8koV2Y6B2oNVu', k5PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJFUzUxMiIsImN0eSI6IkpXVCJ9.eyJhZ2UiOiAyMX0.ANuNdc_lGg6x0xVjvWhUniDbL_1SOErLqtR5SRSb_T7tcsoFyklhmzPtKl0UCCFXia47sVIURnBLQVSX9qcd1EZwAF-3YIds0DL1ZcrcbfFbmoxg8XY1VF6oyTg8ttTgPz2-dZ0WZilBIH9DGzHFwjO89p3LWnxO3-X6hDnJn-buG1jk', k5PubPemP8), true, "1");
});

test("verify test for algorithm PS256 z3", function() {
  expect(3);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.TGkI8x3Be2Z4Hu5c1hP75uMg0XDmDBrqb-pAbp0IbCYElPloOsGVaEqdPqsl8Ck2b3tmMrFtzcUTSYMWncpP4sBlFH5HCVEBo-8Qt23K53wNBM5d13vD0u-GPDUkdz1WbMrGfsOg64yiQrz1aIkLPaKvTN9lOni4hutNHBnIWZA', z3PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.cVJs2mltXOoWwm7nrlf8tdUQ6THB65BD4oVdxhPcvMVv8qZPG8EEjsRzaexevBt_U5yzidkjqcy4eK9A2vJpm1Nx1iMlHlvps1Qp28m9fQcfXDn0UUpMKRCtjeof4Q4y3Luse5tecHkfTClyCvenJ1cCmYsV8QhVATeLy3J4z5g', z3PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzI1NiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.kax6sH0vKJwRE6RJkEZeH0IEPsZ0_KU3QTNBNAeBm677I3OwiZqDb-ryVj442odoUywRiJlSexnz4MbPQ0vCOLT_KvfAVers0NFXJmM6E0vfFfw1Jgs5dNwedBo0BAqD-jL9qS21OBKDb7QCNHDGRiMR6KldGp9v312Vb7HO3GQ', z3PubPemP8), true, "1");
});

test("verify test for algorithm PS384 z3", function() {
  expect(3);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.W7smmk62AVqQvkMUlOOFs251qGFZdq87CqWmExhl1JfKTjadUScrFZQ5_1oaAP234dq8sTG42Sdotvcb_tz15bfR4qHIcNzpHjO0QKNHLe3STLgBuwkFR4O4waaldqqRyqxFbS2zxW6QSbH2mayIm_3ipbL9Evbqm3aC0TcwvnQ', z3PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.BztDRoB11X7HgIpg_uRSMa0T8gkOgHFmlPo8FGkrmDTUnV9ZbO12L7bmOzrbeCbtWOYyVO8XKUfqo8gUATgr6g4IEnpG8HTPZRsouxGvr7YvLp-NHypwtXSxo4U8QCDs--fpOcmTnQpShKOd9EPwuTuoeLjGG6o6DOOu7SgK7EM', z3PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.c7MSE8a-P4OD9gfPEixnS5o1ZgN99yTrt_o2G3OINX47rFOYiVgvrDgrZZXzTFNSZTcuHn4GbU3lB9IWVZMZJl8SE7qdNlSanM9YmkSsYfn4bvGFLdS62yfQWdwM-zngVI2KU5azXXS3DWMjBWrI3hlqqCjdNMMhRWfmoUnzVmc', z3PubPemP8), true, "1");
});

test("verify test for algorithm PS512 z4", function() {
  expect(2);
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzUxMiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.NEI4dMWsOkkwXT1KwOeoG99-CARxw3ChuuFafAEL6MA5pv3karjnqtaGWkCQCfEvvAACQXxUeEnaLT6Gp34HPJF0IS62qLGakOPJQqkfhSOi-Xe1yayqd4vN6YJ7noAial-fI53QqQcGqZ--CveagYOzNm57aOEdrRr0yDJtk3ZGE5qYVsRuqrVx-5UWhJ8NqkQWupx31IXBnWG8YVeoQXw_6DVPYaTDgyHzS8-lh6VQ1CGwPu6t9qjvBymZQnSIYy1sfUjyWCPYMOrO6MdQaTV2Y1mC5J0rZvn2jaA5vWuGn0YwMA2mQt3EFB9pEVpSxS5kAdilVfJq-Rpl4GoH3g', z4PubPemP8), true, "1");
  equal(KJUR.jws.JWS.verify('eyJhbGciOiJQUzUxMiIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.MkwM9gx9CAcRo7x_vJDF23IIpLfB-nY7w5azrbre10OJWeDGPBoZJTJiucXwLzD_C-nrSnnnioTqRm8UeTL9je36HTfAG_8LvWzWUR11WY5SvhYnX-Nynw98I11EKLDGMjrSRUjbPELQICZ8CpniupcH9PCr-ExhcDZtcTVywST5IPsj01fKvtNyFPV-KHFnDEFd2U5MBdOKDOiqU2jrlG6WGKM_irDZ4jw01dSdn4kEsPYYC7U5dsQ91tcpeyGrj0EoD03-NbaHlF9LFd4RH1L2Eglj5zW664X4_86yVtF5inTKZqQHGoQ-KjY2BycJR7_K29Rgrp86SP2SEx4nEw', z4PubPemP8), true, "1");
});

// x. acceptAlgs test
/*
test("arg test", function() {
  expect(1);
  var func1 = function(a, b) {
    return b;
  };
  var result = func1(1);
  equal(result, null, "unspecified arg is null");
});
 */

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-jws-sign.html">asynmetric key(RS/PS/ES) sign/verify</a> | 
<a href="qunit-do-jws-sign-hs.html">Hmac(HS) sign/verify</a> | 
<a href="qunit-do-jws-sign-slow.html">sign/verify slow</a> | 
<a href="qunit-do-jws-intdate.html">IntDate</a> | 
</p>
</body>
</html>

